package com.okilo.online.app.dialog

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import com.okilo.online.app.R
import com.okilo.online.app.common.OkiloComDlog
import com.okilo.online.app.databinding.OkiloDlogRateScoreStarNormalBinding
import com.okilo.online.app.event.OkiloEventPointType
import com.okilo.online.app.tools.helper.OkiloScoreDialogHp

/**
 * OkiloLoan
 * @Author wwdeng
 * @CreateTime: 2024/8/20 16:26
 * @Annotation：评分 Normal
 */
class OkiloRateScoreDlog: OkiloComDlog {
    private lateinit var binding: OkiloDlogRateScoreStarNormalBinding
    private var mCallback: OkiloScoreDialogHp.IStarDialogCallback? = null

    constructor(context: Context) : super(context) {}
    constructor(context: Context, callback: OkiloScoreDialogHp.IStarDialogCallback?) : super(context) {
        mCallback = callback
    }

    override val dialogName: String = "Rate_Us"

    /**
     * 设置点击回调
     */
    fun setOnClick(callback: OkiloScoreDialogHp.IStarDialogCallback){
        this.mCallback = callback
    }

    override fun createOkiloContentView(): View {
        binding = OkiloDlogRateScoreStarNormalBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initializeOkiloViews() {
//        binding.buttonScoreNotNow.paint.flags = Paint.UNDERLINE_TEXT_FLAG//下划线
//        binding.buttonScoreNotNow.paint.isAntiAlias = true//抗锯齿
    }

    override fun setupOkiloEventListeners() {
        setOnClickListener(binding.btnNotNow)
        setOnClickListener(binding.btnRate)

        binding.scoreRatingBar.setIsIndicator(false)
        binding.scoreRatingBar.setOnRatingChangeListener { ratingBar, rating, fromUser ->
            addEventPointRequestAction(OkiloEventPointType.OKILO_CLICK_TRACK.SCORE_STAR,rating.toInt().toString())
        }
    }

    override fun loadOkiloData() {
    }

    override fun onOkiloEventViewClick(v: View?) {
        when(v?.id){
            R.id.btnNotNow -> {//关闭、取消
                addEventPointRequestAction(OkiloEventPointType.OKILO_CLICK_TRACK.SCORE_NOT_NOW,"")
                dismiss()
            }
            else -> {//确定
                val count = binding.scoreRatingBar.rating.toInt()
                if (count <= 0){
                    return
                }
                mCallback?.completeScoringCount(count)
                dismiss()
            }
        }
    }

    fun sOkiloRateScoreTipsText(tips: String?){
        binding.textScoreTips.text = tips
    }
}